﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using TimKen.DataEntity;
using TimKen.App;

namespace TimKen.Web
{
    public class Global : System.Web.HttpApplication
    {
        public override void Init()
        {
            base.Init();
        }
        protected void Application_Start(object sender, EventArgs e)
        {
            
        }
        protected void Application_Error(object sender, EventArgs e)
        {
            Exception ex = Server.GetLastError();

            if (ex != null)
            {
              //  Clogs.LogError("错误信息", ex);
            }

        }
        protected void Application_BeginRequest(Object sender, EventArgs e)
        {
//            //判断如果是HTTP请求,则转换成HTTPS请求,调试时删除，发布前添加

//#if DEBUG
//#else
//            if (!Request.IsSecureConnection)
//                Response.Redirect("https://" + Request.ServerVariables["HTTP_HOST"] + HttpContext.Current.Request.RawUrl, true);
//#endif 
//            string language =  Request.Cookies["Language"] == null ? null : Request.Cookies["Language"].Value;
//            if (!string.IsNullOrEmpty(language))
//            {
//                System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo(language);
//                System.Threading.Thread.CurrentThread.CurrentUICulture = culture;
//                System.Threading.Thread.CurrentThread.CurrentCulture = culture;
//            }
//            else
//            {
//                System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo("zh-CN");
//                System.Threading.Thread.CurrentThread.CurrentUICulture = culture;
//                System.Threading.Thread.CurrentThread.CurrentCulture = culture;
//            }
        }

        public bool isSecureURL
        {
            get
            {
                // Check the request    
                if (HttpContext.Current.Request.IsSecureConnection ||
                    (HttpContext.Current.Request.ServerVariables["HTTPS"] != null &&
                     HttpContext.Current.Request.ServerVariables["HTTPS"].ToLower() == "on"))
                    return true;
                if ((!string.IsNullOrEmpty(HttpContext.Current.Request.ServerVariables["HTTP_HOST"].ToString())) &&
                    (HttpContext.Current.Request.ServerVariables["HTTP_HOST"].ToString().EndsWith("443")))
                    return true; // url is not secure:    
                return false;
            }
        }
     }
}